package com.wlstock.funi.adapter;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TableRow;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import info.zhangxing.ZPagedHScrollTableDataAdapter;

public class WenGuScrollAdapter extends BaseScrollAdapter {

	private Map<Integer, String[]> colHeaders;
	
	private WenGuScrollAdapter(){}
	
	public onRowClick onRowClickListener;
	//rows中外部表示有多少行，内部表示每行里面要显示的数据
	public WenGuScrollAdapter(String [] headers, ArrayList<ArrayList<String>> rows){
		this.headers = headers;
		this.rows = rows;
	}
	
	
	//表格头部
	@Override
	public Map<Integer, String[]> getColHeaders() {
		colHeaders = new HashMap<Integer, String[]>();
		colHeaders.put(ZPagedHScrollTableDataAdapter.SCROLLABLE_COLUMN, this.headers);
		return colHeaders;
	}

	//数据集行数
	@Override
	public int getTotalRows() {
		// TODO Auto-generated method stub
		return this.rows.size();
	}

	@Override
	public List<Map<Integer, List<String>>> getRows(int startRow, int endRow) {
		List<Map<Integer, List<String>>> rows = new ArrayList<Map<Integer, List<String>>>();
		for (int i = startRow; i <= endRow; ++i) {
			Map<Integer, List<String>> row = new HashMap<Integer, List<String>>();
			row.put(ZPagedHScrollTableDataAdapter.SCROLLABLE_COLUMN, this.rows.get(i));
			rows.add(row);
		}
		return rows;
	}

	@Override
	public OnClickListener getOnClickListener(final int row) {
		return  new OnClickListener() {
			@Override
			public void onClick(View v) {
				TableRow tableRow = (TableRow)v;
				if (onRowClickListener!=null) {
					onRowClickListener.rowClick(tableRow,row);
				}
			}
		};
	}

	
	
	public interface onRowClick{
		public void rowClick(TableRow row,int position);
	}

}
